package com.qf.utils;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class CodeUtils {

    public static void main(String[] args) {
        for (int i=0;i<5;i++) {
            System.out.println(createCode(6));
        }
    }

    /**
     * 产生 指定长度的 验证码，都是数值
     * @param size
     * @return
     */
    public static String createCode(int size){
        // 验证码的字符串范围
        List<String> list = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");

        StringBuffer buffer = new StringBuffer();

        for (int i = 0; i < size; i++) {

            // 产生一个list长度范围内的随机下标
            Random random = new Random();
            int index = random.nextInt(list.size());

            buffer.append(list.get(index));

        }

        return buffer.toString();

    }


}
